package com.github.controller;

import com.github.domain.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

/**
 * @author Stephen Liu
 * @version 1.0.0
 * @since 2016/3/30
 */

@Controller
@RequestMapping("/base")
public class BaseController {


    private static Map<String, User> userMap;
    private static User user;

    static {
        userMap = new HashMap<>();
        userMap.put("jack", new User("0001", "jack", "123456"));
        userMap.put("tom", new User("0002", "tom", "123456"));
        userMap.put("kate", new User("0003", "kate", "123456"));
        userMap.put("jerry", new User("0004", "jerry", "123456"));
        userMap.put("jeff", new User("0005", "jeff", "223345632"));
        userMap.put("jackie", new User("0006", "jackie chan", "123456"));
        user = new User("0001", "jack", "123456");
    }

    @ResponseBody
    @RequestMapping(value = "/show/{username}", method = RequestMethod.GET)
    public User show(@PathVariable("username") String username) {

        return userMap.get(username);
    }

    @ResponseBody
    @RequestMapping(value = "/get", method = RequestMethod.POST)
    public User get(@RequestBody User ur) {
        if (ur.getUsername().equals(user.getUsername())) {
            return user;
        }
        return null;
    }

}
